import request from '@/utils/request'
const userApi = {
  Login: '/user/login',
  isLogin: '/user/isLogin',
  checkToken: '/checkTicket',
  Logout: '/logout',
  ForgePassword: '/auth/forge-password',
  Register: '/auth/register',
  twoStepCode: '/auth/2step-code',
  SendSms: '/account/sms',
  SendSmsErr: '/account/sms_err',
  // get my info
  UserInfo: '/user/info',
  UserMenu: '/user/nav',
  UserMenuSso: '/sso/menus',
  getUserInfo: '/sso/userInfo',
}

export function isLogin() {
  return request({
    url: userApi.isLogin,
    method: 'get',
    params: { systemCode: 'OMS' }
  })
}

/**
 * @param parameter
 * @returns {*}
 */
export function login(parameter) {
  return request({
    url: userApi.Login,
    // method: 'get',
    // params: parameter
    method: 'post',
    data: parameter
  })
}

/* 校验登录 */
export function checkToken(parameter) {
  return request({
    url: userApi.checkToken,
    method: 'get',
    params: {...parameter, systemCode: 'OMS'}
  })
}

/* 校验权限 */
export function checkPermission(parameter) {
  return request({
    url: userApi.checkPermission,
    method: 'get',
    params: {...parameter}
  })
}

/* 用户信息 */
export function getUserInfo(parameter) {
  return request({
    url: userApi.getUserInfo,
    method: 'get',
  })
}

export function getSmsCaptcha(parameter) {
  return request({
    url: userApi.SendSms,
    method: 'post',
    data: parameter
  })
}

export function getInfo() {
  return request({
    url: userApi.UserInfo,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    }
  })
}

export function getCurrentUserNav() {
  return request({
    url: userApi.UserMenu,
    method: 'get'
  })
}

export function logout(params) {
  return request({
    url: userApi.Logout,
    method: 'get',
    headers: {
      'Content-Type': 'application/json;charset=UTF-8'
    },
    params
  })
}

/**
 * get user 2step code open?
 * @param parameter {*}
 */
export function get2step(parameter) {
  return request({
    url: userApi.twoStepCode,
    method: 'post',
    data: parameter
  })
}

/* 获取菜单 */
export function getUserMenuSso(parameter) {
  return request({
    url: userApi.UserMenuSso,
    method: 'get',
  })
}
